<script>
import echarts from 'echarts'
import MyChartColor from './MyChartColor'
let getPieRoseOption = function(data){
  let  argumentsObject = arguments
  let legendData = []
  for(let i in data){
    let element = {}
    element['name'] = 'rectangle'
    legendData.push(element)
  }
  let selectedMode = 'single'
  let titleText = ''

  if(data.length === 0){
    data= [
      {
        name : '暂无数据',
        value : 0
      }
    ]
    selectedMode = false
    titleText = '暂无数据'
  }
  
  let option = {
    title :{
      text : titleText,
      x: 'center'
    },
     tooltip: {
      trigger: 'item',
      position: ['50%', '50%'],
      formatter: '{b} : {c} ({d}%)'
    },
    legend :{
      orient : 'vertical',
      y : 'center',
      right : 5,
      formatter (name){
        if(argumentsObject.legend > 1){
          for(let i =1 ; i < argumentsObject.legend ;i++){
            if (argumentsObj[i] === 'legend_val') {
              let target
              for (let i = 0, l = data.length; i < l; i++) {
                if (data[i].name === name) {
                  target = data[i].value
                }
              }
              return name + '：' + target
            }
          }
        }else{
          return echarts.format.truncateText(name, 85, '14px Microsoft Yahei', '…')
        }
      },
      data : legendData
    },
    color : MyChartColor.colorList,
    calculable: true,
    series :[
      {
              type: 'pie',
        selectedMode: selectedMode,
        radius: [20, 110],
        center: ['40%', '50%'],
        roseType: 'radius', // 扇区圆心角展现数据的百分比，半径展现数据的大小
        label: {
          normal: {
            show: false
          },
          emphasis: {
            show: true
          }
        },
        lableLine: {
          normal: {
            show: false
          },
          emphasis: {
            show: true
          }
        },
        data: data
      }
    ]
  }
   return option
}
export default {
  getPieRoseOption
}
</script>
